package org.urbansoft.icl.record;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.urbansoft.icl.field.Field;
import org.urbansoft.icl.field.GenericANField;
import org.urbansoft.icl.field.GenericANSField;
import org.urbansoft.icl.field.GenericBlankField;
import org.urbansoft.icl.field.GenericNBField;
import org.urbansoft.icl.field.GenericNField;
import org.urbansoft.icl.field.Position;
import org.urbansoft.icl.field.Usage;
import org.urbansoft.icl.field.ValidationCriteria;
import org.urbansoft.icl.field.validation.RecordTypeValidator;
import org.urbansoft.icl.field.validation.RoutingNumberValidator;
import org.urbansoft.icl.util.EasternStandardTime;

/**
 * The Class ImageViewDetailRecord.
 */
public class ImageViewDetailRecord extends Record {
	public Field recordType;
	public Field imageIndicator;
	public Field imageCreatorRoutingNumber;
	public Field imageCreatorDate;
	public Field imageViewFormatIndicator;
	public Field imageViewCompressionAlgorithmIdentifier;
	public Field imageViewDataSize;
	public Field viewSideIndicator;
	public Field viewDescriptor;
	public Field digitialSignatureIndicator;
	public Field digitalSignatureMethod;
	public Field securityKeySize;
	public Field startProtectedData;
	public Field lengthProtectedData;
	public Field imageRecreateIndicator;
	public Field userField;
	public Field reserved;
	public Field imgTIFFVarIndicator;
	public Field overrIndicator;
	public Field userField2;

	private static Logger log = Logger.getLogger(ImageViewDetailRecord.class);

	/**
	 * Instantiates a new image view detail record.
	 */
	public ImageViewDetailRecord() {
		fields = new ArrayList<Field>();
		recordName = "Image View Detail Record";
		recordTypeNumber = "50";
		initFields();
	}

	/**
	 * Instantiates a new image view detail record for read purpose
	 */
	public ImageViewDetailRecord(String read) {
		// log.info("New ImageViewDetailRecord for READ");
		fields = new ArrayList<Field>();
		recordName = "Image View Detail Record";
		recordTypeNumber = "50";
		initFields2();
	}

	/**
	 * Instantiates a new image view detail record for write purpose
	 */
	public ImageViewDetailRecord(int read) {
		// log.info("New ImageViewDetailRecord for WRITE");
		fields = new ArrayList<Field>();
		recordName = "Image View Detail Record";
		recordTypeNumber = "50";
		initFields3();
	}

	/**
	 * Inits the fields.
	 */
	private void initFields2() {
		try {
			/* record type */
			recordType = new GenericANField(new Position(1, 2),
					"Image View Detail Record");

			/* image indicator */
			imageIndicator = new GenericANField(new Position(3, 3),
					"Image Indicator");

			/* image creator routing number */
			imageCreatorRoutingNumber = new GenericANField(new Position(4, 12),
					"Image Creator Routing Number");

			/* image creator date */
			imageCreatorDate = new GenericANField(new Position(13, 20),
					"Image Creator Date");

			/* image view format indicator */
			imageViewFormatIndicator = new GenericANField(new Position(21, 22),
					"Image View Format Indicator");

			/* image view compression algorithm identifier */
			imageViewCompressionAlgorithmIdentifier = new GenericNBField(
					new Position(23, 24),
					"Image View Compression Algorithm Identifier");

			/* image view data size */
			imageViewDataSize = new GenericANField(new Position(25, 31),
					"Image View Data Size");

			/* view side indicator */
			viewSideIndicator = new GenericANField(new Position(32, 32),
					"View Side Indicator");

			/* view descriptor */
			viewDescriptor = new GenericANField(new Position(33, 34),
					"View Descriptor");

			/* digital signature indicator */
			digitialSignatureIndicator = new GenericANField(
					new Position(35, 35), "Digital Signature Indicator");

			/*
			 * for the following fields the spec is numeric, but some banks send
			 * blanks
			 */

			/* digital signature method */
			digitalSignatureMethod = new GenericANField(new Position(36, 37),
					"Digital Signature Method");

			/* security key size */
			securityKeySize = new GenericANField(new Position(38, 42),
					"Security Key Size");

			/* start of protected data */
			startProtectedData = new GenericANField(new Position(43, 49),
					"Start Of Protected Data");

			/* length of protected data */
			lengthProtectedData = new GenericANField(new Position(50, 56),
					"Length Of Protected Data");

			/* image recreate indicator */
			imageRecreateIndicator = new GenericANField(new Position(57, 57),
					"Image Recreate Indicator");

			/* user field */
			userField = new GenericANField(new Position(58, 65), "User Field");

			/* Image TIFF Variance Indicator */
			imgTIFFVarIndicator = new GenericANField(new Position(66, 66),
					"Image TIFF Variance Indicator");

			/* user field */
			overrIndicator = new GenericANField(new Position(67, 67),
					"Override Indicator");

			/* reserved */
			reserved = new GenericANField(new Position(68, 80), "Reserved");

			/* user field */
			userField2 = new GenericANField(new Position(81, 90), "User Field");

			fields.add(recordType);
			fields.add(imageIndicator);
			fields.add(imageCreatorRoutingNumber);
			fields.add(imageCreatorDate);
			fields.add(imageViewFormatIndicator);
			fields.add(imageViewCompressionAlgorithmIdentifier);
			fields.add(imageViewDataSize);
			fields.add(viewSideIndicator);
			fields.add(viewDescriptor);
			fields.add(digitialSignatureIndicator);
			fields.add(digitalSignatureMethod);
			fields.add(securityKeySize);
			fields.add(startProtectedData);
			fields.add(lengthProtectedData);
			fields.add(imageRecreateIndicator);
			fields.add(userField);
			fields.add(imgTIFFVarIndicator);
			fields.add(overrIndicator);
			fields.add(reserved);
			fields.add(userField2);
		} catch (Exception e) {
			log.fatal(e.getMessage(), e);
		}
	}

	/**
	 * Inits the fields.
	 */
	private void initFields3() {
		try {
			/* record type */
			recordType = new GenericANField(new Position(1, 2),
					RecordTypeValidator.INSTANCE, "50",
					"Image View Detail Record");

			/* image indicator */
			imageIndicator = new GenericANField(new Position(3, 3),
					"Image Indicator");
			imageIndicator.setFieldData("");

			/* image creator routing number */
			imageCreatorRoutingNumber = new GenericANField(new Position(4, 12),
					"Image Creator Routing Number");
			imageCreatorRoutingNumber.setFieldData("");

			/* image creator date */
			imageCreatorDate = new GenericANField(new Position(13, 20),
					"Image Creator Date");
			imageCreatorDate.setFieldData(EasternStandardTime
					.getCurrentDateInEST());

			/* image view format indicator */
			imageViewFormatIndicator = new GenericANField(new Position(21, 22),
					"Image View Format Indicator");
			imageViewFormatIndicator.setFieldData("");

			/* image view compression algorithm identifier */
			imageViewCompressionAlgorithmIdentifier = new GenericNBField(
					new Position(23, 24),
					"Image View Compression Algorithm Identifier");
			imageViewCompressionAlgorithmIdentifier.setFieldData("");

			/* image view data size */
			imageViewDataSize = new GenericANField(new Position(25, 31),
					"Image View Data Size");
			imageViewDataSize.setFieldData("");

			/* view side indicator */
			viewSideIndicator = new GenericANField(new Position(32, 32),
					"View Side Indicator");
			viewSideIndicator.setFieldData("");

			/* view descriptor */
			viewDescriptor = new GenericANField(new Position(33, 34),
					"View Descriptor");
			viewDescriptor.setFieldData("");

			/* digital signature indicator */
			digitialSignatureIndicator = new GenericANField(
					new Position(35, 35), "Digital Signature Indicator");
			digitialSignatureIndicator.setFieldData("");

			/*
			 * for the following fields the spec is numeric, but some banks send
			 * blanks
			 */

			/* digital signature method */
			digitalSignatureMethod = new GenericANField(new Position(36, 37),
					"Digital Signature Method");
			digitalSignatureMethod.setFieldData("");

			/* security key size */
			securityKeySize = new GenericANField(new Position(38, 42),
					"Security Key Size");
			securityKeySize.setFieldData("");

			/* start of protected data */
			startProtectedData = new GenericANField(new Position(43, 49),
					"Start Of Protected Data");
			startProtectedData.setFieldData("");

			/* length of protected data */
			lengthProtectedData = new GenericANField(new Position(50, 56),
					"Length Of Protected Data");
			lengthProtectedData.setFieldData("");

			/* image recreate indicator */
			imageRecreateIndicator = new GenericANField(new Position(57, 57),
					"Image Recreate Indicator");
			imageRecreateIndicator.setFieldData("");

			/* user field */
			userField = new GenericANField(new Position(58, 65), "User Field");
			userField.setFieldData("");

			/* Image TIFF Variance Indicator */
			imgTIFFVarIndicator = new GenericANField(new Position(66, 66),
					"Image TIFF Variance Indicator");
			imgTIFFVarIndicator.setFieldData("");

			/* user field */
			overrIndicator = new GenericANField(new Position(67, 67),
					"Override Indicator");
			overrIndicator.setFieldData("");

			/* reserved */
			reserved = new GenericANField(new Position(68, 80), "Reserved");
			reserved.setFieldData("");

			/* user field */
			userField2 = new GenericANField(new Position(81, 90), "User Field");
			userField2.setFieldData("");

			fields.add(recordType);
			fields.add(imageIndicator);
			fields.add(imageCreatorRoutingNumber);
			fields.add(imageCreatorDate);
			fields.add(imageViewFormatIndicator);
			fields.add(imageViewCompressionAlgorithmIdentifier);
			fields.add(imageViewDataSize);
			fields.add(viewSideIndicator);
			fields.add(viewDescriptor);
			fields.add(digitialSignatureIndicator);
			fields.add(digitalSignatureMethod);
			fields.add(securityKeySize);
			fields.add(startProtectedData);
			fields.add(lengthProtectedData);
			fields.add(imageRecreateIndicator);
			fields.add(userField);
			fields.add(imgTIFFVarIndicator);
			fields.add(overrIndicator);
			fields.add(reserved);
			fields.add(userField2);

			this.size = 90;
		} catch (Exception e) {
			log.fatal(e.getMessage(), e);
		}
	}

	/**
	 * Inits the fields.
	 */
	private void initFields() {
		try {
			/* record type */
			recordType = new GenericNField(new Position(1, 2),
					RecordTypeValidator.INSTANCE, "50",
					"Image View Detail Record");
			recordType.setValidationCriteria(ValidationCriteria.REQUIRED);

			/* image indicator */
			imageIndicator = new GenericNField(new Position(3, 3),
					"Image Indicator");

			/* image creator routing number */
			imageCreatorRoutingNumber = new GenericNField(new Position(4, 12),
					"Image Creator Routing Number");
			imageCreatorRoutingNumber
					.setValidationCriteria(ValidationCriteria.REQUIRED);
			imageCreatorRoutingNumber
					.setFieldValidator(RoutingNumberValidator.INSTANCE);

			/* image creator date */
			imageCreatorDate = new GenericNField(new Position(13, 20),
					"Image Creator Date");

			/* image view format indicator */
			imageViewFormatIndicator = new GenericNField(new Position(21, 22),
					"Image View Format Indicator");

			/* image view compression algorithm identifier */
			imageViewCompressionAlgorithmIdentifier = new GenericNBField(
					new Position(23, 24),
					"Image View Compression Algorithm Identifier");

			/* image view data size */
			imageViewDataSize = new GenericNField(new Position(25, 31),
					"Image View Data Size");
			imageViewDataSize.setUsage(Usage.CONDITIONAL);

			/* view side indicator */
			viewSideIndicator = new GenericNField(new Position(32, 32),
					"View Side Indicator");

			/* view descriptor */
			viewDescriptor = new GenericNField(new Position(33, 34),
					"View Descriptor");

			/* digital signature indicator */
			digitialSignatureIndicator = new GenericNBField(
					new Position(35, 35), "Digital Signature Indicator");

			/*
			 * for the following fields the spec is numeric, but some banks send
			 * blanks
			 */

			/* digital signature method */
			digitalSignatureMethod = new GenericNBField(new Position(36, 37),
					"Digital Signature Method");
			digitalSignatureMethod.setUsage(Usage.CONDITIONAL);

			/* security key size */
			securityKeySize = new GenericNBField(new Position(38, 42),
					"Security Key Size");
			securityKeySize.setUsage(Usage.CONDITIONAL);

			/* start of protected data */
			startProtectedData = new GenericNBField(new Position(43, 49),
					"Start Of Protected Data");
			startProtectedData.setUsage(Usage.CONDITIONAL);

			/* length of protected data */
			lengthProtectedData = new GenericNBField(new Position(50, 56),
					"Length Of Protected Data");
			lengthProtectedData.setUsage(Usage.CONDITIONAL);

			/* image recreate indicator */
			imageRecreateIndicator = new GenericNBField(new Position(57, 57),
					"Image Recreate Indicator");
			imageRecreateIndicator.setUsage(Usage.CONDITIONAL);

			/* user field */
			userField = new GenericANSField(new Position(58, 65), "User Field");
			userField.setUsage(Usage.CONDITIONAL);

			/* reserved */
			reserved = new GenericBlankField(new Position(66, 80), "Reserved");
			reserved.setFieldData("");

			fields.add(recordType);
			fields.add(imageIndicator);
			fields.add(imageCreatorRoutingNumber);
			fields.add(imageCreatorDate);
			fields.add(imageViewFormatIndicator);
			fields.add(imageViewCompressionAlgorithmIdentifier);
			fields.add(imageViewDataSize);
			fields.add(viewSideIndicator);
			fields.add(viewDescriptor);
			fields.add(digitialSignatureIndicator);
			fields.add(digitalSignatureMethod);
			fields.add(securityKeySize);
			fields.add(startProtectedData);
			fields.add(lengthProtectedData);
			fields.add(imageRecreateIndicator);
			fields.add(userField);
			fields.add(reserved);

		} catch (Exception e) {
			log.fatal(e.getMessage(), e);
		}
	}

}
